﻿namespace Monadic
{
    using System;

    public struct Identity<T>
    {  
        T value;

        public T Value
        {
            get
            {
                return value;
            }
        }

        public Identity(T value)
        {
            this.value = value;
        }

        public Identity<TResult> Select<TResult>(Func<T, TResult> selector)
        {
            return Identity.Create(selector(value));
        }

        public Identity<TResult> SelectMany<U, TResult>(Func<T, Identity<U>> selector, Func<T, U, TResult> resultSelector)
        {
            return Identity.Create(resultSelector(value, selector(value).Value));
        }
    }

    public static class Identity
    {
        public static Identity<T> Create<T>(T value)
        {
            return new Identity<T>(value);
        }
    }
}
